﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using DTO;
//0712455

namespace DAO
{
    public class MoTKTienGuiThanhToanDAO
    {
        public static int Them(KhachHangDTO khDto, LoaiTienTeDTO loaiTTDto, string recentUser)
        {
            SqlConnection cnn = KetNoiCSDL.TaoKetNoi();
            SqlCommand cmd = new SqlCommand("sp_MoTKTienGuiThanhToan", cnn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@HoTen", SqlDbType.NVarChar);
            cmd.Parameters.Add("@CMND", SqlDbType.VarChar);
            cmd.Parameters.Add("@NgayCapCMND", SqlDbType.Date);
            cmd.Parameters.Add("@NoiCapCMND", SqlDbType.NVarChar);
            cmd.Parameters.Add("@DiaChi", SqlDbType.NVarChar);
            cmd.Parameters.Add("@SoDt", SqlDbType.VarChar);

            cmd.Parameters.Add("@ChiNhanhGD", SqlDbType.Int);
            cmd.Parameters.Add("@LoaiTienTe", SqlDbType.Int);


            cmd.Parameters["@HoTen"].Value = khDto.HoTen;
            cmd.Parameters["@CMND"].Value = khDto.CMND;
            cmd.Parameters["@NgayCapCMND"].Value = khDto.NgayCapCMND;
            cmd.Parameters["@NoiCapCMND"].Value = khDto.NoiCapCMND;
            cmd.Parameters["@DiaChiC"].Value = khDto.DiaChi;
            cmd.Parameters["@SoDt"].Value = khDto.SoDT;

            cmd.Parameters["@ChiNhanhGD"].Value = NhanVienDAO.LayChiNhanhGD(recentUser);
            cmd.Parameters["@LoaiTienTe"].Value = loaiTTDto.MaLoaiTienTe;

            cnn.Open();
            int rs = 0;
            try
            {
                rs = (int)cmd.ExecuteNonQuery();
                cnn.Close();
                return rs;
            }
            catch (Exception ex)
            {
                if (cnn.State == ConnectionState.Open)
                    cnn.Close();
                throw ex;
            }
        }
    }
}
